package com.cskaoyan.service;

import com.cskaoyan.bean.*;
import com.cskaoyan.mapper.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminServiceImpl1 implements AdminService1 {
    @Autowired
    AdminMapper1 adminMapper1;

    @Override
    public ListBean queryAdminAddressBean(Integer page, Integer limit, String name, Integer userId, String sort, String order) {
        //分页
        PageHelper.startPage(page, limit);

        //example提供查询条件
        AdminExample1 adminExample = new AdminExample1();
        AdminExample1.Criteria criteria = adminExample.createCriteria();
        if (userId != null) {
            criteria.andUserIdEqualTo(userId);
        }
        if (name != null) {
            criteria.andNameLike("%" + name + "%");
        }
//        userExample.createCriteria().andUsernameLike("%"+username+"%").andMobileEqualTo(mobile);
        adminExample.setOrderByClause(sort + " " + order);
        List<Admin1> admins = adminMapper1.selectByExample(adminExample);

        PageInfo pageInfo = new PageInfo(admins);
        long total = pageInfo.getTotal();

        ListBean listBean = new ListBean();
        listBean.setItems(admins);
//        listBean.setTotal(users.size());
        listBean.setTotal(total);

        return listBean;
    }

}
